package logic

import (
	"context"
	"qianhui/qianhuirpc/qianhuirpc"

	"qianhui/api/internal/svc"
	"qianhui/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ResetPassWordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewResetPassWordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPassWordLogic {
	return &ResetPassWordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ResetPassWordLogic) ResetPassWord(req *types.ResetPassWordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	register, err := l.svcCtx.QianhuiRpc.ResetPassWord(l.ctx, &qianhuirpc.ResetPassWordRequest{
		Account:      req.Account,
		Password:     req.Password,
		Newpassword:  req.Newpassword,
		Newspassword: req.Newspassword,
	})
	if err != nil {
		return nil, err
	}
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "修改密码成功",
		Code:    200,
		Data:    register,
	}, nil

}
